package com.siwei.mes.entity.experiment.concrete.quick;

import com.alibaba.fastjson.JSONObject;
import com.siwei.mes.common.util.JsonUtils;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang.StringUtils;

/**
 * @Description: 目测坍落度  CONCRETE_PARAM_MCTLD
 * @Version: 1.0
 * @author: chenmaolin
 * @date: 2023/12/27 22:27
 */
@Data
@Accessors(chain = true)
public class ConcreteMctld {
    @ApiModelProperty(value = "坍落度1")
    private String tld1 = "";

    @ApiModelProperty(value = "坍落度2")
    private String tld2 = "";

    /**
     * 字符串转成对象 然后再转成json
     *
     * @param object
     * @return
     */
    private static JSONObject toJsonObject(Object object) {
        ConcreteMctld entity = new ConcreteMctld();
        if (object == null) {
            return JsonUtils.beanToObject(entity);
        }
        if (object instanceof String) {
            entity = JsonUtils.getObject((String) object, ConcreteMctld.class);
        } else if (object instanceof JSONObject) {
            entity = JsonUtils.getObject((JSONObject) object, ConcreteMctld.class);
        }
        return JsonUtils.beanToObject(entity);
    }

    /**
     * 检验必填的
     *
     * @param objJson
     * @param name
     * @return
     */
    public static String checkIsMust(JSONObject objJson, String name) {
        if (objJson.isEmpty()) {
            return null;
        }
        ConcreteMctld entity = JsonUtils.getObject(objJson, ConcreteMctld.class);
        if (StringUtils.isBlank(entity.getTld1()) || "null".equals(entity.getTld1())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        if (StringUtils.isBlank(entity.getTld2()) || "null".equals(entity.getTld2())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        return null;
    }
}
